package com.seer.leshantools.server;

import com.google.gson.Gson;
import com.google.gson.annotations.Expose;
import org.eclipse.leshan.server.registration.Registration;

import java.util.UUID;

public class Message {
    /**
     * 唯一号
     */
    private String uuid;
    /**
     * 要发送的数据
     */
    private String data;

    public Registration getRegistration() {
        return registration;
    }

    public void setRegistration(Registration registration) {
        this.registration = registration;
    }

    /**
     * 发送目标
     */
    @Expose
    private Registration registration;
    public Message(String data, Registration registration) {
        this.uuid = UUID.randomUUID().toString().replace("-", "");
        this.data = data;
        this.registration = registration;
    }

    @Override
    public String toString() {
        return "Message{" +
                "uuid='" + uuid + '\'' +
                ", data='" + data + '\'' +
                '}';
    }

    protected Message(String uuid, String data, Registration registration) {
        this.uuid = uuid;
        this.data = data;
        this.registration = registration;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String toJson(Gson gson) {
        return gson.toJson(this);
    }
}
